      *> File Name     000024_Conversion.cbl.
      *> Description   Converting between types.
      *> Project Type  Console application.
      *> CodePlex URL  http://cobol.codeplex.com/
      
      *> Comments      When unboxing from an object to a .NET native
      *>               type, note the following experimentally-
      *>               determined rules:
      *>
      *>                 1) Can't unbox using predefined usage.
      *>                 2) Can't unbox using the .NET type name.
      *>                 3) Must unbox using a name from the repository!
      *>
      *>               These rules apply specifically to .NET native
      *>               types such as System.SByte, System.Int32, etc.
      *>               The code below provides an example.
       
       program-id.   Main.
       repository.
           class sys-console as "System.Console"
           class env         as "System.Environment"
           class sys-sbyte   as "System.SByte"
           .
       working-storage section.
       01  sbyte    sys-sbyte.
       01  int32    binary-long.
       01  double   float-long.
       01  color    type "System.ConsoleColor".
       01  obj      object.
       01  ex       type "System.Exception".
       01  newline  string                       value env::"NewLine".
       procedure division.
           move "Converting Between Types" to sys-console::"Title"
          
           move 42 to sbyte
           move sbyte to int32 *> widening conversion: no problem
           display string::"Format"("SByte {0} becomes Int32 {1}",
               sbyte, int32)
           
           move 3.14159 to double
           move double to int32 *> narrowing conversion: truncated
           display string::"Format"("Double {0} becomes Int32 {1}",
               double, int32)
 
           *>move "foo" to color >* no conversion: won't compile
           
           move sbyte to obj *> implicit boxing
           move sbyte as object to obj *> explicit boxing
           display string::"Format"("SByte {0} becomes Object {1}",
               sbyte, obj) newline

          *> Can't unbox .NET native types using predefined usages:
           try
               move obj as binary-char to sbyte
           catch ex
               display "Statement: move obj as binary-char to sbyte"
               display "   Result: " ex::"GetType" newline
           end-try

          *> Can't unbox .NET native types using .NET type names:
           try
               move obj as type "System.SByte" to sbyte
           catch ex
               display "Statement: move obj as type ""System.SByte"" "
                       "to sbyte"
               display "   Result: " ex::"GetType" newline
           end-try

          *> Must unbox .NET native types using a name from the
          *> repository!
           move obj as sys-sbyte to sbyte
           display "Statement: move obj as sys-sbyte to sbyte"
           display "   Result: Success!" newline
       
           display "Press any key to continue . . . " no advancing
           invoke sys-console::"ReadKey"(true)
           .
       end program   Main.